Skip to content

fix: Fix Grounding e2e test#376

Merged
Jonas-Isr merged 6 commits intomainfrom
fix-grounding-tests
Mar 10, 2025
Merged

fix: Fix Grounding e2e test#376
Jonas-Isr merged 6 commits intomainfrom
fix-grounding-tests

Conversation

@Jonas-Isr
Copy link
Member

Context

Fix the failing grounding e2e test and also fix a small problem in the sample code.

Copy link
Contributor

@newtork newtork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor code inconsistency

Copy link
Contributor

@CharlesDuboisSAP CharlesDuboisSAP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the new endpoint in the HTML homepage, otherwise LGTM

@Jonas-Isr
Copy link
Member Author

Jonas-Isr commented Mar 10, 2025

Add the new endpoint in the HTML homepage, otherwise LGTM

I left it out intentionally because most of the other endpoints are also not part of the HTML page. I did not see a reason to add this when the others like collection/create are not there.

@Jonas-Isr Jonas-Isr enabled auto-merge (squash) March 10, 2025 14:47
final var collections = this.getAllCollections("json");
final var collectionsList = ((CollectionsListResponse) collections).getResources();
var statusCode = 0;
final var deletions = new java.util.ArrayList<>(List.of());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Minor)

Suggested change
final var deletions = new java.util.ArrayList<>(List.of());
final var deletions = new java.util.ArrayList<>();

You could also use an import statement for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly do you mean with using an import statement?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's uncommon to use some basic collection class with fully-qualified name:

new java.util.ArrayList<>();

Because using FQN here implies that there might be a naming conflict with some custom class that's named ArrayList which would very likely result in confusions and mixups: It has a code smell.

Normally, devs would just put an import statement upfront.

import java.util.ArrayList;

new ArrayList<>();

Copy link
Member Author

@Jonas-Isr Jonas-Isr Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry... I was thinking you ment something else (ich stand auf dem Schlauch) 😅

Comment on lines 226 to 242
var statusCode = 0;
final var deletions = new java.util.ArrayList<>(List.of());

for (final var collection : collectionsList) {
if (COLLECTION_TITLE.equals(collection.getTitle())) {
final var deletion = this.deleteDocuments(collection.getId(), "json");
if (deletion instanceof OpenApiResponse) {
final var status = ((OpenApiResponse) deletion).getStatusCode();
deletions.add(deletion);
statusCode = Math.max(status, statusCode);
}
}
}
if ("json".equals(format)) {
return deletions;
}
return statusCode >= 400 ? "Failed to delete collections" : "Deletion successful";
Copy link
Contributor

@newtork newtork Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your loop! For comparison, this is what it would've looked with Stream API
Suggested change
var statusCode = 0;
final var deletions = new java.util.ArrayList<>(List.of());
for (final var collection : collectionsList) {
if (COLLECTION_TITLE.equals(collection.getTitle())) {
final var deletion = this.deleteDocuments(collection.getId(), "json");
if (deletion instanceof OpenApiResponse) {
final var status = ((OpenApiResponse) deletion).getStatusCode();
deletions.add(deletion);
statusCode = Math.max(status, statusCode);
}
}
}
if ("json".equals(format)) {
return deletions;
}
return statusCode >= 400 ? "Failed to delete collections" : "Deletion successful";
final var deletions = new java.util.ArrayList<>();
var statusCode =
collectionsList.stream()
.filter(c -> COLLECTION_TITLE.equals(c.getTitle()))
.map(collection -> this.deleteDocuments(collection.getId(), "json"))
.peek(deletions::add)
.mapToInt(deletion -> ((OpenApiResponse) deletion).getStatusCode())
.max();
if ("json".equals(format)) {
return deletions;
}
return statusCode.orElse(0) >= 400 ? "Failed to delete collections" : "Deletion successful";
However you could still reduce the code a little by dropping the instanceof check
Suggested change
var statusCode = 0;
final var deletions = new java.util.ArrayList<>(List.of());
for (final var collection : collectionsList) {
if (COLLECTION_TITLE.equals(collection.getTitle())) {
final var deletion = this.deleteDocuments(collection.getId(), "json");
if (deletion instanceof OpenApiResponse) {
final var status = ((OpenApiResponse) deletion).getStatusCode();
deletions.add(deletion);
statusCode = Math.max(status, statusCode);
}
}
}
if ("json".equals(format)) {
return deletions;
}
return statusCode >= 400 ? "Failed to delete collections" : "Deletion successful";
var statusCode = 0;
final var deletions = new java.util.ArrayList<>(List.of());
for (final var collection : collectionsList) {
if (COLLECTION_TITLE.equals(collection.getTitle())) {
final var deletion = (OpenApiResponse) this.deleteDocuments(collection.getId(), "json");
deletions.add(deletion);
statusCode = Math.max(deletion.getStatusCode(), statusCode);
}
}
if ("json".equals(format)) {
return deletions;
}
return statusCode >= 400 ? "Failed to delete collections" : "Deletion successful";

(Minor)

  • For consistency, please remove the throw statement in deleteDocuments, the rest of the controller is not throwing (explicitly).
  • Would you mind renaming deleteDocuments to deleteCollection (singular)´? To me it looks like it would tie in better with deleteCollections (plural).

@Jonas-Isr Jonas-Isr merged commit 669d610 into main Mar 10, 2025
6 checks passed
@Jonas-Isr Jonas-Isr deleted the fix-grounding-tests branch March 10, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants